﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace custom
{
    public partial class InputForm : Form
    {
        public string name { get; private set; }
        public string path { get; private set; }
        public string command { get; private set; }
        public string close { get; private set; }

        public InputForm()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            name = textBox1.Text;
            path = textBox2.Text;
            command = textBox3.Text;
            close = textBox4.Text;
            string exePath = Assembly.GetExecutingAssembly().Location; //获取exe程序文件路径
            string pathIni = Path.Combine(Path.GetDirectoryName(exePath), "conf.ini"); //获取conf.ini文件路径
            if (File.Exists(pathIni))
            {
                //判断最后一行是否是空字符串
                string[] lines = File.ReadAllLines(pathIni);
                bool isLastLineEmpty = string.IsNullOrWhiteSpace(lines[lines.Length - 1]);
                using (StreamWriter writer = new StreamWriter(pathIni, true))
                {
                    if (!isLastLineEmpty)
                    {
                        writer.WriteLine("");
                    }
                    writer.WriteLine("[" + name + "]");
                    writer.WriteLine("path=" + path);
                    writer.WriteLine("command=/c " + command);
                    writer.Write("close=/c " + close);
                }

            }
            DialogResult = DialogResult.OK;
            Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            Close();
        }
    }
}
